package com.tekj.cxqcb.view.Module.activity;

import android.content.DialogInterface;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.tekj.cxqcb.MainBActivity;
import com.tekj.cxqcb.R;
import com.tekj.cxqcb.config.enums.EventBusMsgBean;
import com.tekj.cxqcb.operation.BusinessDao;
import com.tekj.cxqcb.operation.resultBean.PubStatusBean;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;
import common.base.activity.BaseActivity;
import common.base.operationHelper.Bean.BindingViewBean;
import common.tool.Tools;
import es.dmoral.toasty.Toasty;

import static com.tekj.cxqcb.config.enums.EventBusMsgBean.EnumStatus.银行卡添加;

/**
 * 添加银行卡
 */
public class AddBankCardActivity extends BaseActivity {
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_l)
    TextView tvL;
    @BindView(R.id.ll_back)
    LinearLayout llBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_r)
    ImageView ivR;
    @BindView(R.id.tv_r)
    TextView tvR;
    @BindView(R.id.ll_right)
    LinearLayout llRight;
    @BindView(R.id.rl_title_bg)
    RelativeLayout rlTitleBg;
    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.et_sfz)
    EditText etSfz;
    @BindView(R.id.et_yhkh)
    EditText etYhkh;
    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.tv_add)
    TextView tvAdd;

    BusinessDao mod5Dao;

    @Override
    public void init() {
        tvTitle.setText("添加银行卡");
        mod5Dao = new BusinessDao(activity, this);
    }

    @Override
    public int setLayout() {
        return R.layout.activity_add_bank_card;
    }

    @Override
    public void initLoadStart() {
        showDialog();
    }

    @Override
    public void initLoadEnd() {
        dialog.dismiss();
    }

    @Override
    public void initBindingView(Object mBean) {
        BindingViewBean bindingViewBean = (BindingViewBean) mBean;
        switch (bindingViewBean.getmEnumStatus()) {
            case 添加银行卡:
                PubStatusBean bean = (PubStatusBean) bindingViewBean.getBean();
                if (bean.getCode().equals("0000000")) {
                    activity.finish();
                    EventBus.getDefault().post(new EventBusMsgBean(银行卡添加,""));
                }
                Toasty.normal(activity, bean.getMsg()).show();
                break;

        }
    }

    String name, userIdCard, cardNumber, phone;

    @OnClick({R.id.ll_back, R.id.tv_add})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_back:
                finish();
                break;
            case R.id.tv_add:
                name = etName.getText().toString().trim();
                userIdCard = etSfz.getText().toString().trim();
                cardNumber = etYhkh.getText().toString().trim();
                phone = etPhone.getText().toString().trim();
                if (name.equals("") || userIdCard.equals("") || cardNumber.equals("") || phone.equals("")) {
                    Toasty.normal(activity, "请先填写信息").show();
                    return;
                }
                Tools.showNormalDialogOne(activity, "银行卡提交", "提交确认", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mod5Dao.InsertUserBank(MainBActivity.User.getUserId(),
                                name, userIdCard, cardNumber, phone);

                    }
                }, null);

                break;
        }
    }
}
